package com.example.config.exception;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ErrorResponse {

    private String code;
    private String message;
    private LocalDateTime timestamp;
    private String path;

    // 或者不使用 Lombok，手动实现 builder
    public static ErrorResponseBuilder builder() {
        return new ErrorResponseBuilder();
    }

    // 手动实现的 Builder 类
    public static class ErrorResponseBuilder {
        private String code;
        private String message;
        private LocalDateTime timestamp;
        private String path;

        public ErrorResponseBuilder code(String code) {
            this.code = code;
            return this;
        }

        public ErrorResponseBuilder message(String message) {
            this.message = message;
            return this;
        }

        public ErrorResponseBuilder timestamp(LocalDateTime timestamp) {
            this.timestamp = timestamp;
            return this;
        }

        public ErrorResponseBuilder path(String path) {
            this.path = path;
            return this;
        }

        public ErrorResponse build() {
            ErrorResponse response = new ErrorResponse();
            response.setCode(code);
            response.setMessage(message);
            response.setTimestamp(timestamp != null ? timestamp : LocalDateTime.now());
            response.setPath(path);
            return response;
        }
    }
}
